#include <vector>

using std::vector;

class Solution {
public:
    bool isValidSudoku(vector<vector<char>>& board) {
        vector<int> v1(10, 0);
        vector<int> v2(10, 0);
        vector<int> v3(10, 0);
        for (int i = 0; i < 9; i++) {
            v1.assign(10, 0);
            v2.assign(10, 0);
            for (int j = 0; j < 9; j++) {
                int num1 = board[i][j] == '.' ? 0 : board[i][j] - '0';
                int num2 = board[j][i] == '.' ? 0 : board[j][i] - '0';
                if (v1[num1] > 0 || v2[num2] > 0) {
                    return false;
                }
                else {
                    if (num1 > 0) {
                        v1[num1] = 1;
                    }
                    if (num2 > 0) {
                        v2[num2] = 1;
                    }
                }
            }
        }
        v1.assign(10, 0);
        v2.assign(10, 0);
        for (int i = 0; i < 9; i++) {
            if (i % 3 == 0) {
                v1.assign(10, 0);
                v2.assign(10, 0);
                v3.assign(10, 0);
            }
            for (int j = 0; j < 3; j++) {
                int num1 = board[i][j] == '.' ? 0 : board[i][j] - '0';
                int num2 = board[i][j + 3] == '.' ? 0 : board[i][j + 3] - '0';
                int num3 = board[i][j + 6] == '.' ? 0 : board[i][j + 6] - '0';
                if (v1[num1] > 0 || v2[num2] > 0 || v3[num3] > 0) {
                    return false;
                }
                else {
                    if (num1 > 0) {
                        v1[num1] = 1;
                    }
                    if (num2 > 0) {
                        v2[num2] = 1;
                    }
                    if (num3 > 0) {
                        v3[num3] = 1;
                    }
                }
            }
        }
        return true;
    }
};